﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace SharedGenomics.Core.Collections
{
    public class BoundedTimedBuffer<T> : TimedBuffer<T>
    {
        private readonly int _signalSize;

        public BoundedTimedBuffer(int signalSize, TimeSpan signalTimeout, Action callback)
            : base(signalTimeout, callback)
        {
            signalSize.ThrowIfLessThan(1, "signalSize");
            this._signalSize = signalSize;
        }

        protected override bool ShouldNotify()
        {
            return base.ShouldNotify() || this.BufferCount >= this._signalSize;
        }
    }
}
